'''
Created on 2012-7-27

@author: game-netease
'''
import Config
import pygame
from pygame.locals import *


image_mgr = {}
font_mgr = {}

def loadFront(fontname, size): 
    if Config.robot_client:
        return None
    if fontname == None:
        return None
    
    global font_mgr
    key  = (fontname,size)
    if font_mgr.has_key(key):
        font_mgr[key][1] +=1
        return font_mgr[key][0]
    else:
        font = pygame.font.Font(r'resource/raw/'+fontname, size)
        font_mgr[key]=[font,1]
        return font
    
def loadImage(name): 
    if Config.robot_client:
        return None
    if name == None:
        return None
    
    global image_mgr
    if image_mgr.has_key(name):
        image_mgr[name][1] +=1
        return image_mgr[name][0]
    else:
        img = pygame.image.load(name).convert_alpha()
        image_mgr[name]=[img,1]
        return img
    
def releaseImage(name):
    global image_mgr
    if image_mgr.has_key(name):
        image_mgr[name][1]-=1
        if image_mgr[name][1] <= 0:
            del image_mgr[name]        